package util

import (
	"agent-list---web-development/list/model"
	"github.com/jinzhu/gorm"
	"math/rand"
	"time"
)

func RandomString(db *gorm.DB) string {
	var letters = []byte("1234567890")
	result := make([]byte, 7)
	rand.Seed(time.Now().Unix())
	for i := range result {
		result[i] = letters[rand.Intn(len(letters))]
	}

	var user model.User
	db.Where("account=?", result).First(&user)
	if user.Id == 0 {
		return string(result)
	}
	return RandomString(db)
}
